package com.xhwl.centiotdata.handler.pedestrian.impl;

import com.xhwl.centiotdata.handler.pedestrian.PedestrianIntegrationFactory;
import com.xhwl.centiotdata.handler.pedestrian.PedestrianIntegrationHandler;
import com.xhwl.centiotdata.pojo.dto.pedestrian.PedestrianIntegrationConfigDTO;
import com.xhwl.centiotdata.pojo.dto.younijia.PedestrianRecordYouNiJiaDTO;
import com.xhwl.centiotdata.service.cent.IPedestrianCentService;
import com.xhwl.centiotdata.suppliersystem.younijia.PedestrianYouNiJiaHandler;
import com.xhwl.common.dto.cent.pedes.OpenDoorRecordDTO;
import com.xhwl.common.enums.ProductEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author msy
 */
@Service
@Slf4j
public class PedestrianIntegrationYouNiJiaHandler extends PedestrianIntegrationHandler {

    @Autowired
    private PedestrianYouNiJiaHandler pedestrianYouNiJiaHandler;

    @Autowired
    private IPedestrianCentService pedestrianCentService;


    @Override
    public void afterPropertiesSet() throws Exception {
        PedestrianIntegrationFactory.register(ProductEnum.YOUNIJIA_PEDESTRIAN.getId(), this);
    }

    @Override
    public void pullVisits(PedestrianIntegrationConfigDTO configDTO, Date date) {
        // 拉取数据
        List<PedestrianRecordYouNiJiaDTO> recordYouNiJiaDTOList = pedestrianYouNiJiaHandler.pullVisits(configDTO, date);
        if (CollectionUtils.isEmpty(recordYouNiJiaDTOList)) {
            return;
        }
        // 转换数据
        List<OpenDoorRecordDTO> openDoorRecordDTOList = pedestrianYouNiJiaHandler.handleRecord(configDTO, recordYouNiJiaDTOList);
        // 存储业务中台
        pedestrianCentService.saveBatch(openDoorRecordDTOList);
    }
}
